// 秒 转换成 天时分
export const getLotteryPeriod = (value: number = 0) => {
    const defaultValue = value > 0 ? 0 : '';
    return {
        value1: parseInt((value / 1440).toString()) || defaultValue,
        value2: parseInt(((value % 1440) / 60).toString()) || defaultValue,
        value3: (value % 1440) % 60 || defaultValue,
    };
};

export const getLotteryPeriodText = (value: number = 0) => {
    const advanceNotice: ObjValueAny = getLotteryPeriod(value);
    const dd = advanceNotice.value1 ? `${advanceNotice.value1}天` : '';
    const hh = advanceNotice.value2 ? `${advanceNotice.value2}时` : '';
    const mm = advanceNotice.value3 ? `${advanceNotice.value3}分` : '';
    return `${dd}${hh}${mm}`;
};

// 天时分 转换成 秒
export const setAdvanceNotice = (lottery: ObjValueAny = {}) => {
    let value1 = parseInt(((lottery.value1 || 0) * 24 * 60).toString());
    let value2 = parseInt(((lottery.value2 || 0) * 60).toString());
    let value3 = parseInt((lottery.value3 || 0).toString());
    return value1 + value2 + value3;
};


/**
 * 获取指定日期 时间戳
 * @param date 不传值当前时间
 */
export const getDateParse = (date: string | null = null): number => {
    if (date) {
        const _dateParse = Date.parse(date.replace(/-/g, '/'));
        return _dateParse || 0;
    } else {
        return Date.parse(new Date().toString());
    }
}

/**
 * 天数的时间戳
 * @param day 天数
 */
export const getDayParse = (day: number = 1) => {
    return 1000 * 60 * 60 * 24 * day;
}

/**
 * element 日期范围选择 禁用
 * 只能选择指定日期 之前或之后
 */
const oneDayParse: number = getDayParse(1);// 一天的时间戳
// 日期有时分秒 且 不为00:00:00
export const dateIsTime = (date: string) => {
    const d = new Date(date);
    return !!(d.getHours() || d.getMinutes() || d.getSeconds());
}

// 禁用指定时间之前 不包括指定时间
export const disBeforeDay = (date: string | null = null) => {
    if (date) {
        return (time: Date) => {
            // 如果日期有时分秒 减一天 否则不减
            return (time.getTime() as number) < getDateParse(date) - (dateIsTime(date) ? oneDayParse : 0);
        }
    } else {
        return (time: Date) => {
            return (time.getTime() as number) < Date.now() - oneDayParse
        }
    }
}